
package com.idealighter.game.games.foursshop.struct;

import com.idealighter.game.core.common.Game;
import com.idealighter.game.dictionary.domain.FoursShopRoomDomain;
import com.idealighter.game.games.common.AbstractRoom;
import com.idealighter.game.games.common.AbstractSeat;
import com.idealighter.game.games.common.AbstractTable;
import com.idealighter.game.games.foursshop.manager.FoursShopDataMgr;
import com.idealighter.game.server.context.ApplicationContext;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

/**
 * 4s . shopRoom.
 */
public class FoursShopRoom extends AbstractRoom {

  // 桌子
  public final Map<Integer, FoursShopTable> tables;

  //
  // @Inject
  //// FoursShopMgr foursShopMgr;
  public FoursShopRoom(FoursShopRoomDomain roomDomain) {
    super(roomDomain.getId(), roomDomain.getName());
    this.tables = createTables(roomDomain.getId(), roomDomain.getTable(), roomDomain.getChair());
  }

  /**
   * 创建桌子 .
   * 
   * @param num .
   * @return
   */
  private Map<Integer, FoursShopTable> createTables(int roomId, int num, int chairs) {
    if (num > 1) {
      num = 1;
    }
    Map<Integer, FoursShopTable> tables = new HashMap<>();
    for (int i = 0; i < num; i++) {
      int tableId = 1;
      tables.put(tableId, new FoursShopTable(tableId, this, chairs));
      // foursShopMgr.doRest(roomId, tableId);
    }

    return tables;
  }

  @Override
  public Game game() {
    return Game.FOURS_SHOP;
  }

  @Override
  public AbstractSeat seat(long playerId) {

    return ApplicationContext.getBean(FoursShopDataMgr.class).getPlayerSeat(playerId);
  }

  @Override
  public Collection<? extends AbstractTable> tables() {

    return tables.values();
  }

}
